# zope imports
from zope.component import adapts
from zope.interface import implements
from zope.interface import Interface

# EasyArticle imports
from easyarticle.core.interfaces import IData

class GenericData(object):
    """An generic adapter for to provide some data for sub objects of an 
    EasyArticle components. Developers can provide more specific ones for their 
    own content objects.
    """
    implements(IData)
    adapts(Interface)

    def __init__(self, context):
        """        
        """
        self.context = context
        
    def getContent(self):
        """
        """
        return {        
            "portal_type" : self.context.getPortalTypeName(),
            "id"          : self.context.getId(),
            "title"       : self.context.Title(),
            "url"         : self.context.absolute_url(),
            "description" : self.context.Description(),
        }
    
    def getEditUrls(self):
        """
        """
        parent = self.context.aq_inner.aq_parent
        
        edit_url   = "%s/base_edit" % self.context.absolute_url()
        delete_url = "%s/ea_delete_confirmation" % self.context.absolute_url()
        up_url     = "%s/ea_folder_position?position=up&id=%s" % (
                        parent.absolute_url(), 
                        self.context.getId())
        down_url   = "%s/ea_folder_position?position=down&id=%s" % (
                        parent.absolute_url(), 
                        self.context.getId())

        return {
            "edit_url"   : edit_url,
            "delete_url" : delete_url,
            "up_url"     : up_url,
            "down_url"   : down_url,
        }
        
    def getData(self):
        """
        """
        content = self.getContent()
        content.update(self.getEditUrls())

        return content